package kr.hkit.androidcomplete02.cp;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class ProductCursorAdapterDBHelper extends SQLiteOpenHelper {

	public ProductCursorAdapterDBHelper(Context context) {
		super(context, "ProductCursorAdapter.db", null, 1);
	}


	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE product (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, price INTEGER);");
		db.beginTransaction();
		for(int i=0; i<100; i++) {
			db.execSQL("INSERT INTO product VALUES (null, '오징어 땅콩', 900);");
			db.execSQL("INSERT INTO product VALUES (null, '농심 포테이토 칩', 2000);");
			db.execSQL("INSERT INTO product VALUES (null, '로보트 태권 V', 1000);");
			db.execSQL("INSERT INTO product VALUES (null, '꼬마 자동차 붕붕', 1500);");
			db.execSQL("INSERT INTO product VALUES (null, '윈도우즈 API 정복', 32000);");
			db.execSQL("INSERT INTO product VALUES (null, '롯데 인벤스 아파트', 190000000);");
			db.execSQL("INSERT INTO product VALUES (null, '88 라이트', 1900);");
			db.execSQL("INSERT INTO product VALUES (null, '프라이드 1.6 CVVT 골드', 8900000);");
			db.execSQL("INSERT INTO product VALUES (null, '캐리비안 베이 입장권', 25000);");
		}
		db.setTransactionSuccessful();
		db.endTransaction();
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS product");
		onCreate(db);
	}

}
